﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ProcessManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ProcessManagement.ProcessRouteVMs
{
    public partial class ProcessRouteListVM : BasePagedListVM<ProcessRoute_View, ProcessRouteSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProcessRoute_View>> InitGridHeader()
        {
            return new List<GridColumn<ProcessRoute_View>>{
                
                this.MakeGridHeader(x => x.ProcessRoute_RoutingName).SetTitle(@Localizer["Page.工艺路线名称"].Value),
                this.MakeGridHeader(x => x.ProcessRoute_RoutingCode).SetTitle(@Localizer["Page.工艺路线编码"].Value),
                this.MakeGridHeader(x => x.ProcessRoute_ProductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.ProcessRoute_ProductCode).SetTitle(@Localizer["Page.产品编码"].Value),
                this.MakeGridHeader(x => x.ProcessRoute_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.ProcessRoute_Active).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.ProcessRoute_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProcessRoute_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProcessRoute_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProcessRoute_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProcessRoute_View> GetSearchQuery()
        {
            var query = DC.Set<ProcessRoute>()
                
                .CheckContain(Searcher.RoutingName, x=>x.RoutingName)
                .CheckContain(Searcher.RoutingCode, x=>x.RoutingCode)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductCode, x=>x.ProductCode)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckEqual(Searcher.Active, x=>x.Active)
                .CheckContain(Searcher.Aux_1, x=>x.Aux_1)
                .CheckContain(Searcher.Aux_2, x=>x.Aux_2)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProcessRoute_View
                {
				    ID = x.ID,
                    
                    ProcessRoute_RoutingName = x.RoutingName,
                    ProcessRoute_RoutingCode = x.RoutingCode,
                    ProcessRoute_ProductId = x.ProductId,
                    ProcessRoute_ProductCode = x .Product.Code,
                    ProcessRoute_ProductName = x.Product.Name,
                    ProcessRoute_Active = x.Active,
                    ProcessRoute_CreateTime = x.CreateTime,
                    ProcessRoute_UpdateTime = x.UpdateTime,
                    ProcessRoute_CreateBy = x.CreateBy,
                    ProcessRoute_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProcessRoute_View: ProcessRoute
    {
        
        public string ProcessRoute_RoutingName { get; set; }
        public string ProcessRoute_RoutingCode { get; set; }
        public long? ProcessRoute_ProductId { get; set; }
        public string ProcessRoute_ProductCode { get; set; }
        public string ProcessRoute_ProductName { get; set; }
        public bool? ProcessRoute_Active { get; set; }
        public DateTime? ProcessRoute_CreateTime { get; set; }
        public DateTime? ProcessRoute_UpdateTime { get; set; }
        public string ProcessRoute_CreateBy { get; set; }
        public string ProcessRoute_UpdateBy { get; set; }

    }

}